import dashboard from './modules/dashboard' // 工作台模块路由
import basePage from './modules/basePage' // 动态页面路由
import system from './modules/system' // 系统设置
import commodity from './modules/commodity' // 商品管理
import basics from './modules/basics' // 商品基础管理
import finance from './modules/finance' // 财务管理
import sourcing from './modules/sourcing' // 寻源
import stock from './modules/stock' // 存量管理
import supplier from './modules/supplier' // 供应商系统
import purchase from './modules/purchase' // 采购系统
import BasicLayout from '@/layouts/basic-layout'

/**
 * 在主框架内显示
 */

const frameIn = [
  {
    path: '/',
    redirect: {
      name: 'todoCenter'
    },
    component: BasicLayout,
    children: [
      {
        path: 'index',
        name: 'index',
        redirect: {
          name: 'todoCenter'
        }
      },
      {
        path: 'log',
        name: 'log',
        meta: {
          title: '前端日志',
          auth: true
        },
        component: () => import('@/pages/system/log')
      },
      // 刷新页面 必须保留
      {
        path: 'refresh',
        name: 'refresh',
        hidden: true,
        component: {
          beforeRouteEnter (to, from, next) {
            next(instance => instance.$router.replace(from.fullPath))
          },
          render: h => h()
        }
      },
      // 页面重定向 必须保留
      {
        path: 'redirect/:route*',
        name: 'redirect',
        hidden: true,
        component: {
          beforeRouteEnter (to, from, next) {
            next(instance =>
              instance.$router.replace(JSON.parse(from.params.route))
            )
          },
          render: h => h()
        }
      },
      {
        path: '/todoCenter',
        name: 'todoCenter',
        component: () => import('@/pages/system/toDoCenter'),
      }
    ]
  },
  dashboard,
  system,
  commodity,
  basics,
  finance,
  sourcing,
  stock,
  supplier,
  purchase,
  basePage
]

/**
 * 错误页面
 */

const errorPage = [
  {
    path: '/403',
    name: '403',
    meta: {
      title: '403'
    },
    component: () => import('@/pages/system/error/403')
  },
  {
    path: '/500',
    name: '500',
    meta: {
      title: '500'
    },
    component: () => import('@/pages/system/error/500')
  },
  {
    path: '*',
    name: '404',
    meta: {
      title: '404'
    },
    component: () => import('@/pages/system/error/404')
  }
]

// 导出需要显示菜单的
export const frameInRoutes = frameIn

// 重新组织后导出
export default [...frameIn, ...errorPage]
